import axios from './axios';

/**
 * 产品检验报告API
 */
const productInspectionApi = {
  /**
   * 获取指定溯源码的所有检验报告
   * @param {string} traceabilityCode 溯源码
   * @returns {Promise} API响应
   */
  getByTraceabilityCode(traceabilityCode) {
    return axios.get(`/ProductInspectionReport/${traceabilityCode}`);
  },

  /**
   * 获取指定ID的检验报告
   * @param {number} id 报告ID
   * @returns {Promise} API响应
   */
  getById(id) {
    return axios.get(`/ProductInspectionReport/detail/${id}`);
  },

  /**
   * 添加产品检验报告
   * @param {string} traceabilityCode 溯源码
   * @param {File} file 报告图片文件
   * @returns {Promise} API响应
   */
  addReport(traceabilityCode, file) {
    const formData = new FormData();
    formData.append('file', file);
    
    return axios.post(`/ProductInspectionReport/${traceabilityCode}/upload`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  /**
   * 删除产品检验报告
   * @param {number} id 报告ID
   * @returns {Promise} API响应
   */
  deleteReport(id) {
    return axios.delete(`/ProductInspectionReport/${id}`);
  }
};

export default productInspectionApi; 